package cmd

import (
	"errors"
	"github.com/spf13/cobra"
	"os"
	"tyjt-ferry/cmd/cobraapi"
	"tyjt-ferry/cmd/cobramigrate"
	"tyjt-ferry/pkg/logger"
)

var rootCmd = &cobra.Command{
	Use:               "ferry",
	Short:             "-v",
	SilenceErrors:     true,
	DisableAutoGenTag: true,
	Long:              `ferry`,
	Args: func(cmd *cobra.Command, args []string) error {
		if len(args) < 1 {
			return errors.New("requires at least one arg")
		}
		return nil
	},
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		return nil
	},
	Run: func(cmd *cobra.Command, args []string) {
		usageStr := `欢迎使用 ferry，可以使用 -h 查看命令`
		logger.Info(usageStr)
	},
}

func init() {
	rootCmd.AddCommand(cobraapi.StartCmd)
	rootCmd.AddCommand(cobramigrate.StartCmd)
}

func Execute() {
	if err := rootCmd.Execute(); err != nil {
		logger.Error("启动失败：%v", err)
		os.Exit(-1)
	}
}
